function txt2TypeTxt(txt, messages) {
	const codeStartMatch = txt.match(/```\w+\r?\n/)
	
	if (codeStartMatch) {
		messages.push({
			txt: txt.substring(0, codeStartMatch.index),
			type: 'txt'
		})

		const strLen =  codeStartMatch[0].length
		const codeEndIndex = txt.indexOf('```', codeStartMatch.index + strLen)

		if (codeEndIndex > -1) {
			messages.push({
				txt: txt.substring(codeStartMatch.index + strLen, codeEndIndex),
				type: 'code'
			})

			if (codeEndIndex + 2 < txt.length - 1) {
				messages = txt2TypeTxt(txt.substring(codeEndIndex + 3), messages)
			}
		} else {
			messages.push({
				txt: txt.substring(codeStartMatch.index + strLen),
				type: 'code'
			})
		}
	} else {
		messages.push({
			txt,
			type: 'txt'
		})
	}
	
	return messages
	
}

export function chatTxtHandle(txt) {
	const messages = []
	
	return txt2TypeTxt(txt, messages)
}
